package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    // region 员工增删改查

    /**
     * 根据[用户名]查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from sky_take_out.employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 根据[id]查询员工信息
     *
     * @param userId
     * @return
     */
    Employee getByUserId(Long userId);

    /**
     * 多条件查询
     *
     * @param employee
     * @return
     */
    List<Employee> query(Employee employee);

    /**
     * 添加员工
     *
     * @param employee
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into sky_take_out.employee " +
            "(name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
            "values " +
            "(#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void insert(Employee employee);

    /**
     * 条件查询
     * todo 这里仅提供了一个参数的条件查询，可以改为多参数查询
     *
     * @param name
     * @return
     */
    Page<Employee> pageQuery(String name);

    /**
     * 更新员工信息
     *
     * @param employee
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Employee employee);

    // endregion
}
